import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import java.sql.SQLException;

public class Main {
    public static void main(String[] args){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/jdbc");
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("20050324");
        dataSource.setInitialSize(5);//初始化连接池数量
        dataSource.setMaxActive(10);// 最大连接池数量
        dataSource.setMinIdle(5);// 最小连接池数量
        dataSource.setMaxWait(5000);// 最大等待时间
        dataSource.setValidationQuery("select 1");// 用来检测连接是否有效的sql
        try {
                DruidPooledConnection connection = dataSource.getConnection();
                if(connection!=null){
                    System.out.println("连接成功！");
                }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}